package com.ai.entity.made.page;

import com.ai.entity.BasePage;
import com.ai.entity.made.camera.CameraPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CameraPage extends BasePage<CameraPO> {

    @ApiModelProperty(value = "摄像头名")
    private String nickname;

    @ApiModelProperty(value = "摄像头IP")
    private String ip;

    @ApiModelProperty(value = "服务器ID")
    private Integer serverId;

    @ApiModelProperty(value = "状态(1.开，2.关，-1.弃用)")
    private Integer state;

    @ApiModelProperty(value = "摄像头ids")
    private List<String> cameraCodes;

    @ApiModelProperty(value = "区域codes")
    private List<String> regionCodes;


    @Override
    public QueryWrapper<CameraPO> getQuery(QueryWrapper<CameraPO> queryWrapper) {
        return queryWrapper
                .like((!StringUtils.isEmpty(nickname)), "camera.nickname", nickname)
                .like((!StringUtils.isEmpty(ip)), "camera.ip", ip)
                .eq((serverId != null && serverId != 0), "camera.server_id", serverId)
                .eq((state != null && state != 0), "camera.state", state)
                .gt("camera.state", 0)
                .in(!CollectionUtils.isEmpty(cameraCodes),"camera.code",cameraCodes)
                .ge((!com.alibaba.druid.util.StringUtils.isEmpty(getDatebegin())), "camera.create_time", getDatebegin())
                .lt((!com.alibaba.druid.util.StringUtils.isEmpty(getDateend())), "camera.create_time", getDateend())
                .orderByDesc("camera.create_time");
    }
}
